package ebj.common.reflection;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.TypeVariable;

import ebj.common.domain.Person;
import ebj.common.utils.Utils;


/**
 * 反射实例10：通过反射调用其他类中的方法
 * @author zhouxiangyong
 * @version $Id$
 */
public class ReflectClient10 {
	public static void main(String[] args) {
		String clazzName = Utils.getProperty("Person");
		Class<?> clazz = null;
		Person person = null;
		try {
			clazz = Class.forName(clazzName);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		try {
			person = (Person) clazz.newInstance();
			Method method = clazz.getDeclaredMethod("friendlyMethod", String.class);
			// 抑制java的访问控制检查，否则将不能实例化该友好方法
			method.setAccessible(true);
			method.invoke(person, "北京欢迎你");
			Method method2 = clazz.getDeclaredMethod("privateMethod");
			// 抑制java的访问控制检查，否则将不能实例化该私有方法
			method2.setAccessible(true);
			method2.invoke(person);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		}
	}
}
